package com.jxdinfo.hussar.example.sbjx.tree.service.impl;

import com.jxdinfo.hussar.support.mp.base.service.impl.HussarServiceImpl;
import com.jxdinfo.hussar.support.datasource.annotations.HussarDs;
import com.jxdinfo.hussar.platform.core.utils.HussarUtils;
import com.jxdinfo.hussar.support.exception.HussarException;
import com.jxdinfo.hussar.example.sbjx.tree.model.Tree;
import com.jxdinfo.hussar.example.sbjx.tree.service.TreeService;
import com.jxdinfo.hussar.example.sbjx.tree.dao.TreeMapper;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import com.jxdinfo.hussar.common.tfmodel.TfModelEnum;
import com.jxdinfo.hussar.example.sbjx.tree.vo.TreePageVO;
import com.jxdinfo.hussar.platform.core.base.apiresult.ApiResponse;

/**
 * 树服务实现类
 */
@Service("sbjx.tree.TreeServiceImpl")
@HussarDs("master")
public class TreeServiceImpl extends HussarServiceImpl<TreeMapper, Tree> implements TreeService {

    private static final Logger logger = LoggerFactory.getLogger(TreeServiceImpl.class);

    private static final String RETURN_CODE = "0";

    @Override
    public ApiResponse<TreePageVO> hussarQuery() {
        try {
            TreePageVO treePageVO = new TreePageVO();
            List<Tree> list = this.list();
            treePageVO.setData(list);
            if (HussarUtils.isNotEmpty(list)) {
                treePageVO.setCount((long) list.size());
            }
            treePageVO.setCode(RETURN_CODE);
            return ApiResponse.success(treePageVO);
        } catch (Exception e) {
            throw new HussarException(TfModelEnum.TF_FORM_QUERY_FAILED.getMessage());
        }
    }
}
